package sixth.group.controller;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import sixth.group.domain.Customer;
import sixth.group.domain.CustomerExample;
import sixth.group.domain.Restaurant;
import sixth.group.domain.RestaurantExample;
import sixth.group.service.WyxAdministratorService;
import sixth.group.utils.MessageAndData;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

//也应该纳入到Spring容器中管理，但是Controller和用户直接交互，建议分离spring，此例采用spring-mvc
//如何称为一个Controller呢
@Controller
//Controller和用户交互， 用户一般HTTP协议访问Controller，给不同的Controller和不同的方法映射不同的url地址，进行匹配
@RequestMapping(value = "/WyxAdministor")

public class WyxAdministorController {

    @Autowired
    private WyxAdministratorService wyxAdministratorService;

    @RequestMapping("/resLook")   // 拼接结果   应用发布地址+类映射地址+方法映射地址  http://localhost:8088/Java-project-training/WyxAdministor/resLook
    @ResponseBody           //返回给客户端的是json数据
    public MessageAndData resLook(){
        List<Restaurant> WyxAllres  = wyxAdministratorService.resLook();
        MessageAndData Wyxreslist = MessageAndData.success().add("Wyxreslist",WyxAllres);
        return Wyxreslist;

        //在console输出 controller测试用
//        System.out.println(WyxAllres.toString());
//        System.out.println(111111);

    }


    @RequestMapping("/cusLook")
    @ResponseBody           //返回给客户端的是json数据
    public MessageAndData cusLook(){
        List<Customer> WyxAllcus  = wyxAdministratorService.cusLook();
        MessageAndData Wyxcuslist = MessageAndData.success().add("Wyxcuslist",WyxAllcus);
        return Wyxcuslist;

        //在console输出 controller测试用
//        System.out.println(WyxAllcus.toString());
//        System.out.println(222222);
}

    @RequestMapping(value = "/resDelete")
   // @ResponseBody           //返回给客户端的是json数据
    public ModelAndView resDelete(@RequestParam int rid){
        int ri= wyxAdministratorService.resDelete(rid);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("redirect:../WyxResDelete.html");//设置视图页   , 默认springmvc使用了视图解析器，会自动填充前缀和后缀
        return modelAndView;
        //MessageAndData msg = MessageAndData.success().add("ri",ri);
        //return msg;
        //在console输出 controller测试用
        //System.out.println(333333);
    }

    @RequestMapping(value ="/cusDelete")
//    @ResponseBody           //返回给客户端的是json数据
    public ModelAndView cusDelete(@RequestParam int cid){
        int ci= wyxAdministratorService.cusDelete(cid);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("redirect:../WyxCusDelete.html");//设置视图页   , 默认springmvc使用了视图解析器，会自动填充前缀和后缀
        return modelAndView;

//        MessageAndData msg = MessageAndData.success().add("ci",ci);
//        return msg;
//        在console输出 controller测试用
//        System.out.println(4444444);
    }

}
